home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 July & August / PCWorld_2007-07-08_cd.bin / komunikace / ie7pro / IE7proSetup.exe / {app} / plugins / serverinfo / plugin.js
Text File  |  2007-04-23  |  3KB  |  117 lines

  1. // ==UserScript==
  2. // @name          Server Info
  3. // @namespace     http://iescripts.org
  4. // @description      Display the Websites IP Address, Web Server and last modified time
  5. // @statussize    84
  6. // ==/UserScript==
  7.  
  8. (function()
  9. {
  10.     var plugin = PRO_plugin(@name);
  11.     plugin.onpagechange = handlePageChange;
  12.     plugin.registerContextMenu("Site uptime/WebServer", menuShowNetcraft);
  13.     plugin.registerContextMenu("Domain Name Owner", menuShowDNSOwner);
  14.     plugin.registerContextMenu("Server Location", menuShowServerLocation);
  15.     
  16.     
  17.     var gCookie = "";
  18.     var gFindIP = "";
  19.     var gFindServer = "";
  20.       
  21.     var reqObj = new Object();
  22.     reqObj.request = function(callback, cookie, url, userAgent, lastModify,qtype) {
  23.         var req;
  24.         req = PRO_xmlhttpRequest();
  25.         req.onreadystatechange = function() {
  26.             if (req.readyState == 4) {// completed
  27.                 if (req.status < 400) {// only if "OK"
  28.                     try {
  29.                         callback(req, cookie);
  30.                     } catch(err) {
  31.                     }
  32.                 } else {
  33.                     // PRO_log("There was a problem loading data :\n" + req.status+ "/" + req.statusText);
  34.                 }
  35.                 setTimeout(function() {req.forceClean();req = null;}, 1000);
  36.             }
  37.         }
  38.         try {
  39.             req.open(qtype, url);
  40.             req.setRequestHeader( "User-Agent", userAgent);
  41.             if(lastModify.length > 0)
  42.                 req.setRequestHeader( "If-Modified-Since", lastModify);
  43.             req.send(null);
  44.         
  45.         } catch(err){ 
  46.         }
  47.         return req;
  48.     }
  49.  
  50.     // escape the url
  51.     function encodeURL(url)
  52.     {
  53.         return escape(url).replace(/\+/g, '%2B').replace(/\"/g, '%22').replace(/\'/g, '%27');
  54.     }
  55.     
  56.     function menuShowNetcraft(cookie,url) {
  57.     var urlhost = url.split("/");
  58.       var qhost = urlhost[2];
  59.     PRO_openInTab("http://uptime.netcraft.com/up/graph/?host="+qhost,1);
  60.     }
  61.  
  62.     function menuShowDNSOwner(cookie,url) {
  63.     var urlhost = url.split("/");
  64.         var qhost = urlhost[2];
  65.         PRO_openInTab("http://www.dnsstuff.com/tools/whois.ch?ip="+qhost+"&src=ShowIP",1);
  66.     }
  67.  
  68.     function menuShowServerLocation(cookie,url) {
  69.     var urlhost = url.split("/");
  70.         var qhost = urlhost[2];
  71.         PRO_openInTab("http://ip2country.esymbian.info/?host="+qhost,1);
  72.     }
  73.  
  74.     function handlePageChange(cookie, url, state) {
  75.     var urlhost = url.split("/");
  76.         var qhost = urlhost[2];
  77.         gCookie = cookie;
  78.  
  79.         if(state == 1) {// page loading
  80.             gFindIP =  plugin.getServerIp(qhost);
  81.             plugin.setStatusInfo("", gFindIP, "", gCookie);                    
  82.         } else if(state == 2) {// page loaded
  83.             gFindIP =  plugin.getServerIp(qhost);
  84.             if(plugin.getTabValue(cookie,"serverinfo_oldip") != gFindIP) {
  85.                 reqObj.request(processFindServerData, cookie, url, "User-Agent", "Mozilla/4.0 (compatible; Windows XP 5.1)","HEAD");
  86.             }else{
  87.                 gFindServer = plugin.getTabValue(cookie,"serverinfo_oldserver");
  88.                 processResult();
  89.             }
  90.         }
  91.     }
  92.  
  93.  
  94.     function processFindServerData(req, cookie) {
  95.         var lastm = req.getResponseHeader('Last-Modified');
  96.         var webserver = req.getResponseHeader('Server');
  97.         
  98.         if(gCookie == cookie) {
  99.             var FindServer = "<b>Web Server:</b> " + webserver + "<br><b>Last Modified:</b> " + lastm;
  100.             gFindServer = FindServer;
  101.             plugin.setTabValue(cookie,"serverinfo_oldserver",gFindServer);
  102.             plugin.setTabValue(cookie,"serverinfo_oldip",gFindIP);
  103.             processResult();
  104.         }else{
  105.         }
  106.     }
  107.  
  108.     function processResult()
  109.     {
  110.         var tips = gFindServer + "<br><b>IP:</b> " + gFindIP;
  111.         plugin.setStatusInfo("", gFindIP, tips, gCookie);
  112.     }
  113. }
  114. )();
  115.  
  116.  
  117.